<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
  <meta name="description" content="">
  <meta name="author" content="ThemeBucket">
  <link rel="shortcut icon" href="#" type="image/png">

  <title>货品信息</title>

  <!--data table-->
  <link rel="stylesheet" href="js/data-tables/DT_bootstrap.css" />

  <link href="css/style.css" rel="stylesheet">
  <link href="css/style-responsive.css" rel="stylesheet">

  <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!--[if lt IE 9]>
  <script src="js/html5shiv.js"></script>
  <script src="js/respond.min.js"></script>
  <![endif]-->

    <style type="text/css">
        #all_light,#all_light_w { /*整个弹窗的页面*/
            opacity: 0.8; /*透明度*/
            width: 100%; /*宽度*/
            height: 2300px; /*高度，不能百分百*/
            background: #000; /*背景色*/
            position: absolute;
            top: 0;
            left: 0; /*定位*/
            display: none; /*隐藏*/
            z-index: 2; /*覆盖*/
        }
        #contes,#contes_w { /* 弹框的页面*/
            width: 500px; /*宽度*/
            height: 500px; /*高度*/
            background: #fff; /*背景色*/
            display: none; /*隐藏*/
            z-index: 2; /*覆盖*/
            position: absolute;
            top: 100px;
            left: 400px; /* 定位*/
        }
        input{
            margin-bottom: 10px;
        }
    </style>

</head>

<body class="sticky-header">


<!--  弹框的div==================================================================================== -->
<div id="contes" style="">
    <div style="width:500px;height:40px;">

        <hr>
        <form style=" margin-left: 100px;" id="dataform">
            <input type="hidden" id="id" name="id">
            货品分类名称  :  <input type="text" value="" id="name"  name="name"><br>
            货品总量  :  <input type="text" value="" id="sum"  name="sum"><br>
            货品成本  :  <input type="text" value="" id="perCost" name="perCost"><br>
            货品单价  :  <input type="text" value="" id="perPrice" name="perPrice"><br>
            货品总价  :  <input type="text" value="" id="sumPrice" name="sumPrice"><br>
            所属仓库id  :  <input type="text" value="" id="wid" name="wid"><br>
              <input type="hidden" id="lastProtectTime" value="" name="lastProtectTime">
            最近保养时间  :  <input type="text" value="" id="lastProtectTimeStr"  readonly="readonly" name="lastProtectTimeStr"><br>
            保养警戒天数  :  <input type="text" value="" id="dangerTime" name="dangerTime" ><br>
            库存警戒总数  :  <input type="text" value="" id="dangerSum"  name="dangerSum" ><br>

            <button type="submit" onclick="submithuoform()">提交</button>
            <button type="button" onclick="cancel()">取消</button>
        </form>
    </div>
</div>
<div id="all_light">
</div>
<!--  弹框的div==================================================================================== -->

<!--  仓库弹框的div==================================================================================== -->
<div id="contes_w" style="">
    <div style="width:500px;height:40px;">
        <hr>

        <h1> ==========仓库信息==========</h1>
        <form style=" margin-left: 100px;" id="dataform_w">
            <input type="hidden" id="wwid" name="id">

            仓库容量   :  <input type="text" value="" id="capacity"  name="capacity"><br>
            仓库存储类型   :  <input type="text" value="" id="desp"  name="desp"><br>

            <button type="submit" onclick="submitwform()">提交</button>
            <button type="button" onclick="cancelw()">取消</button>

        </form>
        <h1> ==========仓库信息==========</h1>
    </div>
</div>
<div id="all_light_w">
</div>
<!--  仓库弹框的div==================================================================================== -->
<section>
    <!-- left side start-->
    <script src="left.js"></script>
    <!-- left side end-->
    
    <!-- main content start-->
    <div class="main-content" >

        <!-- header section start-->
        <div class="header-section">

        <!--toggle button start-->
        <a class="toggle-btn"><i class="fa fa-bars"></i></a>
        <!--toggle button end-->


        </div>
        <!-- header section end-->

        <!-- page heading start-->
        <div class="page-heading">
            <h3>
                货品管理
            </h3>
            <ul class="breadcrumb">
                <li>
                    <a href="#">首页</a>
                </li>
                <li>
                    <a href="#">管理</a>
                </li>
                <li class="active"> 货品管理 </li>
            </ul>
        </div>
        <!-- page heading end-->

        <!--body wrapper start-->
        <div class="wrapper">
             <div class="row">
                <div class="col-sm-12">
                <section class="panel">
                <header class="panel-heading">

                    <span class="tools pull-right">
                        <a href="javascript:;" class="fa fa-chevron-down"></a>
                        <a href="javascript:;" class="fa fa-times"></a>
                     </span>
                </header>
                <div class="panel-body">
                <div class="adv-table editable-table ">
                <div class="clearfix">
                    <div class="btn-group">
                        <button id="editable-sample_new" class="btn btn-primary" onclick="addHuo()">
                            货品添加 <i class="fa fa-plus"></i>
                        </button>

                    </div>
                    <div class="btn-group pull-right">
                        <button class="btn btn-default dropdown-toggle" data-toggle="dropdown">Tools <i class="fa fa-angle-down"></i>
                        </button>
                        <ul class="dropdown-menu pull-right">
                            <li><a href="#">Print</a></li>
                            <li><a href="#">Save as PDF</a></li>
                            <li><a href="#">Export to Excel</a></li>
                        </ul>
                    </div>
                </div>
                <div class="space15"></div>
                    <!-- 表格 -->
                    <table class="table table-striped table-hover table-bordered"
                           id="editable-sample">
                        <thead>
                        <tr>
                            <th prop="id">货品分类id</th>
                            <th prop="name">货品分类名称</th>
                            <th prop="sum">货品总量</th>
                            <th prop="per_cost">单个成本</th>
                            <th prop="per_price">货品单价</th>
                            <th prop="sum_price">货品总价</th>
                            <th prop="wid">所属仓库</th>
                            <th prop="lastProtectTimeStr">最近保养时间</th>
                            <th prop="dangerTime">保养警戒天数</th>
                            <th prop="dangerSum">库存警戒总数</th>
                            <th>货品保养</th>
                            <th>修改</th>
                            <th>删除</th>
                        </tr>
                        </thead>

                        <tbody id="newList">

                        </tbody>
                    </table>
                </div>

                </div>
                    <div col-lg-6>

                        <div class="dataTables_paginate paging_bootstrap pagination">

                            <ul id="pagination">

                            </ul>
                        </div>
                    </div>
                </section>
                </div>
                </div>
        </div>
        <!--body wrapper end-->


        <!--        仓库管理-------------------------------------------->
        <div class="row">
            <div class="col-sm-12">
                <section class="panel">
                    <header class="panel-heading">
                        仓库信息<br>
                        <span class="tools pull-right">
                <a href="javascript:;" class="fa fa-chevron-down"></a>
                <a href="javascript:;" class="fa fa-times"></a>

             </span>
                    </header>
                    <div class="panel-body">
                        <div class="adv-table">
                            <div class="btn-group">
                                <button  class="btn btn-primary" onclick="addw()">
                                    添加仓库 <i class="fa fa-plus"></i>
                                </button>
                            </div>


                            <table class="display table table-bordered" id="hidden-table-info-2">
                                <thead>
                                <tr>
                                    <th prop="wwid">仓库号</th>
                                    <th prop="capacity">仓库容量</th>
                                    <th prop="desp">仓库存储类型</th>
                                    <th>编辑</th>
                                    <th>删除</th>
                                </tr>
                                </thead>
                                <tbody id="wlist">

                                </tbody>
                            </table>

                        </div>
                    </div>
                </section>
            </div>
        </div>
        <!--        仓库管理------------------------------------------->


    </div>
    <!-- main content end-->
</section>

<!-- Placed js at the end of the document so the pages load faster -->
<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/jquery-ui-1.9.2.custom.min.js"></script>
<script src="js/jquery-migrate-1.2.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/modernizr.min.js"></script>
<script src="js/jquery.nicescroll.js"></script>

<!--data table-->
<script type="text/javascript" src="js/data-tables/jquery.dataTables.js"></script>
<script type="text/javascript" src="js/data-tables/DT_bootstrap.js"></script>

<!--common scripts for all pages-->
<script src="js/scripts.js"></script>

<!--script for editable table-->
<script src="js/editable-table.js"></script>

<!-- END JAVASCRIPTS -->
<script src="orders.js"></script>
<script>
    window.onload=function (){
        var order;
        $.ajax({
            url:"/users/getOrder",
            type:"get",
            contentType:"application/json;charset=UTF8",
            dataType:"json",
            success:function (res){
                order=res;
                if(order==2){
                    order2();
                }
                if(order==3){
                    order3();
                }
            },
            error:function (){

            }
        })

        load();
    }
    var pagination={ //分页信息
        currentPage:1,
        pageSize:5,
        totalPage:10
    }
    //数据列表

    var list=[]

    // 弹窗start
    function cancel(){
        document.getElementById('contes').style.display = 'none';
    }
    function jump() {

        document.getElementById('all_light');
        document.getElementById('contes').style.display = 'block';
    }
    //弹窗end

    //序列化Json
    function getFormJson(form) {
        var o = {};
        var a = form
        $.each(a, function () {
            if (o[this.name] !== undefined) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        });
        return o;
    }
    //提交修改
    function submithuoform(){
        var serialize = $("#dataform").serializeArray();
        var huopin=getFormJson(serialize);
        console.log(huopin)

        $.ajax({ //更新和添加用同一个接口即可
            url:"/huopin/updateOrAdd",
            type:"POST",
            data: JSON.stringify(huopin),
            contentType:"application/json;charset=UTF8",
            dataType:"json",
            success:function (res){
                if (res.success){
                    alert(res.msg);
                }
                else{
                    alert("操作失败!")
                }
            },
            error:function (){
                alert("莫名错误")
            }
        })

    }

    //添加
    function addHuo(){
        $("#dataform")[0].reset();
        $("#id").val(0);
        jump();
    }
    //保养
    function baoyang(id){
        $.ajax({
            url:"/huopin/baoyang/"+id,
            type:"GET",
            contentType:"application/json;charset=UTF8",
            dataType:"json",
            success:function (res){
                    if (res.success){
                        alert(res.msg);
                }
                else{
                    alert("查询失败!")
                }
            },
            error:function (){

            }
        })
    }
    //修改
    function edit(id){
        $.ajax({
            url:"/huopin/getById/"+id,
            type:"GET",
            contentType:"application/json;charset=UTF8",
            dataType:"json",
            success:function (res){
                if (res.success){
                    var user=res.data
                    $("#id").val(user.id);
                    $("#name").val(user.name);
                    $("#sum").val(user.sum);
                    $("#perPrice").val(user.perPrice);
                    $("#sumPrice").val(user.sumPrice);
                    $("#wid").val(user.wid);
                    $("#lastProtectTime").val(user.lastProtectTime);
                    $("#lastProtectTimeStr").val(user.lastProtectTimeStr);
                    $("#dangerTime").val(user.dangerTime);
                    $("#dangerSum").val(user.dangerSum);
                }
                else{
                    alert("查询失败!")
                }
            },
            error:function (){

            }
        })

        jump();
    }

    //删除人员
    function delU(id) {

        $.ajax({
            url:"/huopin/del/"+id,
            type:"GET",
            contentType:"application/json;charset=UTF8",
            dataType:"json",
            success:function (res){
                if (res.success){
                    alert("删除成功!")
                }
                else{
                    alert("删除失败!")
                }
            },
            error:function (){

            }
        })
    }
    //展示列表
    function showList(list,sum,index){
        $('#newList').empty();
        for(var i=0;i<list.length;i++) {

            var tr="<tr>\n" +
                "<td>"+list[i].id+"</td>\n" +
                "<td>"+list[i].name+"</td>\n" +
                "<td>"+list[i].sum+"</td>\n" +
                "<td>"+list[i].perCost+"</td>\n" +
                "<td>"+list[i].perPrice+"</td>\n" +
                "<td>"+list[i].sumPrice+"</td>\n" +
                "<td>"+list[i].wid+"</td>\n" +
                "<td>"+list[i].lastProtectTimeStr+"</td>\n" +
                "<td>"+list[i].dangerTime+"</td>\n" +
                "<td>"+list[i].dangerSum+"</td>\n" +
                "<td><button type='submit' style='background-color: #0de2c2' onclick=\"baoyang("+list[i].id+")\">货品保养</button></td>\n" +
                "<td><button style='background-color: #55d455 ' onclick=\"edit("+list[i].id+")\">修改</button></td>\n" +
                "<td><button type='submit' style='background-color: #ff3948;color: black' onclick=\"delU("+list[i].id+")\">删除</button></td>\n" +
                "</tr>"
            $("#newList").append(tr);
        }

        $('#pagination').empty();
        for(var i=1;i<=sum;i++){
            if(i==index)var li="<li><button style='color: red' onclick=\"gopage("+i+")\">"+i+"</button></li>";
            else var li="<li><button onclick=\"gopage("+i+")\">"+i+"</button></li>";
            $("#pagination").append(li);
        }
    }
    //仓库管理
    function getwlist() {
        $.ajax({
            url:"/utils/getwlist",
            type:"GET",
            contentType:"application/json;charset=UTF8",
            dataType:"json",
            success:function (res){
                if (res.success){
                    var list=res.data;
                    showwlist(list)
                }
                else{
                    alert("查询失败!")
                }
            },
            error:function (){

            }
        })

    }
    function editw(id){
        $.ajax({
            url:"/utils/getwById/"+id,
            type:"GET",
            contentType:"application/json;charset=UTF8",
            dataType:"json",
            success:function (res){
                if (res.success){
                    var data=res.data
                    $("#wwid").val(data.id);
                    $("#capacity").val(data.capacity);
                    $("#desp").val(data.desp);
                    jumpw()
                }
                else{
                    alert("查询失败!")
                }
            },
            error:function (){
            }
        })
    }
    function delw(id){
        $.ajax({
            url:"/utils/delwById/"+id,
            type:"GET",
            contentType:"application/json;charset=UTF8",
            dataType:"json",
            success:function (res){
                alert(res.msg)
            },
            error:function (){
            }
        })
    }
    function showwlist(list){
        $('#wlist').empty();
        for(var i=0;i<list.length;i++) {
            var tr="<tr>\n" +
                "<td>"+list[i].id+"</td>\n" +
                "<td>"+list[i].capacity+"</td>\n" +
                "<td>"+list[i].desp+"</td>\n" +
                "<td><button style='background-color: #55d455; ' onclick=\"editw("+list[i].id+")\">修改</button></td>\n" +
                "<td><button style='background-color: red;color: black ' onclick=\"delw("+list[i].id+")\">删除</button></td>\n" +
                "</tr>"
            console.log(tr)
            $("#wlist").append(tr);
        }
    }
    //添加供货商
    function addw(){
        $("#dataform_w")[0].reset();
        $("#wwid").val(0)
        jumpw()
    }
    function jumpw(){
        document.getElementById('all_light_w');
        document.getElementById('contes_w').style.display = 'block';
    }
    function cancelw(){
        document.getElementById('contes_w').style.display = 'none';
    }
    //提交修改仓库
    function submitwform(){
        var serialize = $("#dataform_w").serializeArray();
        var wParmas=getFormJson(serialize);
        console.log(wParmas)
        $.ajax({ //更新和添加用同一个接口即可
            url:"/utils/wupdateOrAdd",
            type:"POST",
            data: JSON.stringify(wParmas),
            contentType:"application/json;charset=UTF8",
            dataType:"json",
            success:function (res){
                if (res.success){
                    alert(res.msg);
                }
                else{
                    alert("操作失败!")
                }
            },
            error:function (){
                alert("莫名错误")
            }
        })

    }
    //仓库管理

    //去xx页面
    function gopage(i){
        // $('#newList').empty();
        pagination.currentPage=i;//修改当前页码
        $.ajax({
            url:"/huopin/getList",
            type:"POST",
            data:'{"currentPage":"'+pagination.currentPage+'","pageSize":"'+pagination.pageSize+'"}',
            contentType:"application/json;charset=UTF8",
            dataType:"json",
            success:function (res){
                if (res.success){
                    var l=res.data.list//重新赋值
                    var sum=res.data.totalPage;//更新总页数
                    showList(l,sum,i)
                }
                else{
                    alert("查询失败!")
                }
            },
            error:function (){

            }
        })


    }
    function load(){
        gopage(1);
        getwlist();
    }




</script>


</body>
</html>
